package ipmsg.file;

import ipmsg.etc.GlobalVar;
import ipmsg.etc.UtilityGlobal;
import java.util.Vector;












public class ConfigBlacklist
{
  static String path;
  
  public static void readConfig()
  {
    try
    {
      path = GlobalVar.USER_HOME + GlobalVar.FILE_PATH_DELIMITER + ".LanMsg_ipMsg" + GlobalVar.FILE_PATH_DELIMITER + "BlackList.conf";
      



      ConfigOperation config = new ConfigOperation(path);
      
      String blacklist = config.getValue("blacklist");
      
      if ((blacklist == null) || (blacklist.equals(""))) {
        return;
      }
      
      String[] blacklists = blacklist.split(";");
      

      for (int i = blacklists.length - 1; i >= 0; i--) {
        if (UtilityGlobal.isIP(blacklists[i])) {
          GlobalVar.BLACK_LIST.add(blacklists[i]);
        }
      }
    } catch (ConfigurationException ex) {
      errorHappen();
    }
  }
  
  public static void writeConfig()
  {
    try
    {
      ConfigOperation config = new ConfigOperation(path);
      
      StringBuffer sb = new StringBuffer();
      
      for (int i = GlobalVar.BLACK_LIST.size() - 1; i > 0; i--) {
        sb.append((String)GlobalVar.BLACK_LIST.get(i) + ";");
      }
      if (GlobalVar.BLACK_LIST.size() > 0) {
        sb.append((String)GlobalVar.BLACK_LIST.get(0));
      }
      config.setValue("blacklist", sb.toString());
      config.saveFile();
    }
    catch (ConfigurationException ex)
    {
      ex.printStackTrace();
    }
  }
  
  private static void errorHappen()
  {
    UtilityConfig.creatFile(path, '\000');
  }
}
